var data1 = getUrlQueryString('index');
var data2 ;
var submitSno;
$.ajax({
    url:"/RuanJianKeShe/getAllStuByCno",
    type:"post",
    data:{
        "msg":"getAllStuByCno",
        "cno":data1
    },
    dataType:"json",
    success:function(data){
        showAllStudentByCno(data.snoAndGradeList);
    },
    error:function(){
        alert("fail");
    }
})
function showAllStudentByCno(data) {
    var str = "";
    for (var i = 0; i < data.length; i++) {
        submitSno = data[i].sno;
        var submitGrade = data[i].grade;
        str = "<tr>" +
            "<td>" + data[i].sno +  "</td>" +
            "<td>" + data[i].sname + "</td>" +
            "<td>" + "<input id='gradeIpt' value="+submitGrade+"></input>" + "</td>" +
            "<td>" + "<button  onclick=\"updateHandle("+submitSno+")\">提交</button>" +
            "</td><td></td>" +
            "</tr>";
        $("#tab").append(str);
        $("#gradeIpt").attr("id",submitSno);
    }
}
updateHandle = function (data3) {
    data2 = document.getElementById(data3).value;
    $.ajax({
        url: "/RuanJianKeShe/updataGrade",
        type: "post",
        data: {
            "msg":"updataGrade",
            "sno":data3,
            "cno":data1,
            "grade":data2
        },
        dataType: "json",
        success: function () {
            alert("success");
        },
        error: function () {
            alert("fail");
        }
    })
}

function getUrlQueryString(names, urls) {
    urls = urls || window.location.href;
    urls && urls.indexOf("?") > -1 ? urls = urls
        .substring(urls.indexOf("?") + 1) : "";
    var reg = new RegExp("(^|&)" + names + "=([^&]*)(&|$)", "i");
    var r = urls ? urls.match(reg) : window.location.search.substr(1)
        .match(reg);
    if (r != null && r[2] != "")
        return unescape(r[2]);
    return null;
};